#![feature(test)]

extern crate rmp_serde as rmps;
use rmpv;
extern crate test;

use test::Bencher;

use rmpv::ValueRef;

// Encoded value: [1, 0, [[["127.0.0.1", 59074]], 1, {0: ["read", {}, {0: ["value", {}], 1: ["error", {}]}], 1: ["write", {}, {0: ["value", {}], 1: ["error", {}]}], 2: ["remove", {}, {0: ["value", {}], 1: ["error", {}]}], 3: ["find", {}, {0: ["value", {}], 1: ["error", {}]}]}], [[80, 81, 82]]].
const COMPLEX: &[u8] = &[
    0x94, 0x01, 0x00, 0x93, 0x91, 0x92, 0xa9, 0x31,
    0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31,
    0xcd, 0xe6, 0xc2, 0x01, 0x84, 0x00, 0x93, 0xa4,
    0x72, 0x65, 0x61, 0x64, 0x80, 0x82, 0x00, 0x92,
    0xa5, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x80, 0x01,
    0x92, 0xa5, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x80,
    0x01, 0x93, 0xa5, 0x77, 0x72, 0x69, 0x74, 0x65,
    0x80, 0x82, 0x00, 0x92, 0xa5, 0x76, 0x61, 0x6c,
    0x75, 0x65, 0x80, 0x01, 0x92, 0xa5, 0x65, 0x72,
    0x72, 0x6f, 0x72, 0x80, 0x02, 0x93, 0xa6, 0x72,
    0x65, 0x6d, 0x6f, 0x76, 0x65, 0x80, 0x82, 0x00,
    0x92, 0xa5, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x80,
    0x01, 0x92, 0xa5, 0x65, 0x72, 0x72, 0x6f, 0x72,
    0x80, 0x03, 0x93, 0xa4, 0x66, 0x69, 0x6e, 0x64,
    0x80, 0x82, 0x00, 0x92, 0xa5, 0x76, 0x61, 0x6c,
    0x75, 0x65, 0x80, 0x01, 0x92, 0xa5, 0x65, 0x72,
    0x72, 0x6f, 0x72, 0x80, 0x91, 0x93, 0x50, 0x51,
    0x52,
];

#[bench]
fn from_complex_read_value_ref(b: &mut Bencher) {
    b.iter(|| {
        let res = rmpv::decode::read_value_ref(&mut &COMPLEX[..]).unwrap();
        test::black_box(res);
    });
    b.bytes = COMPLEX.len() as u64;
}

#[bench]
fn from_complex_zero_copy_decode(b: &mut Bencher) {
    b.iter(|| {
        let res: ValueRef<'_> = rmps::from_slice(&COMPLEX[..]).unwrap();
        test::black_box(res);
    });
    b.bytes = COMPLEX.len() as u64;
}

